﻿using System;
// 原文中抽象类的例子其实没有体现多态性，可以再加一个继承类（三角形面积），以体现多态。
namespace PolymorphismApplication
{
    abstract class Shape
    {
        public abstract int Area();
    }

    class Rectangle : Shape
    {
        private int length;
        private int width;

        public Rectangle(int a = 0, int b = 0)
        {
            length = a;
            width = b;
        }

        public override int Area()
        {
            //Console.WriteLine("Rectangle 类的面积：");
            return (width * length);
        }
    }

    class Triangle : Shape
    {
        private int baseLine;
        private int height;

        public Triangle(int a = 0, int b = 0)
        {
            baseLine = a;
            height = b;
        }

        public override int Area()
        {
            //Console.WriteLine("三角形 类的面积：");
            return (2 * baseLine * height / 4);
        }
    }

    class RectangleTester
    {
        static void Main(string[] args)
        {
            Rectangle r = new Rectangle(10, 7);
            double a = r.Area();
            Triangle t = new Triangle(10, 7);
            double b = t.Area();
            Console.WriteLine("长方形面积：{0}，三角形面积：{1}", a, b);
            Console.ReadKey();
        }
    }
}